const ad = document.querySelector('.ad');
const closeBtn = document.querySelector('.close');

// 广告出现和关闭
setTimeout(function () {
    ad.style.display = 'block';
    ad.style.position = 'fixed';
}, 800);

closeBtn.addEventListener('click', function () {
    ad.style.display = 'none';
})

const fixSearch = document.querySelector('.fix_search');
const tuijian = document.querySelector('.tuijian');
const topBtn = document.querySelector('.top_btn');
let tjTop = tuijian.offsetTop;
console.log(tjTop);
document.addEventListener('scroll', function () {
    if (window.pageYOffset >= tjTop) {
        fixSearch.style.display = 'block';
        fixSearch.style.zIndex = '99999';
        topBtn.style.display = 'block';
    } else {
        fixSearch.style.display = 'none';
        topBtn.style.display = 'none';
    }
})

// 返回顶部
function animate(obj, target, callback) {
    obj, timer = setInterval(function () {
        let step = (target - window.pageYOffset) / 10;
        step = step > 0 ? Math.ceil(step) : Math.floor(step);
        if (window.pageYOffset == target) {
            clearInterval(obj.timer);
        }
        callback && callback();
        window.scroll(0, window.pageYOffset + step);
    }, 15)
}
topBtn.addEventListener('click', function () {
    animate(window, 0);
})

// 秒杀板块
const killer = document.querySelector('.kill_box');
const lis = killer.querySelectorAll('li');

countDown('2022.10.31 24:00');
setInterval(function () {

    countDown('2022.10.31 24:00');
}, 1000)
function countDown(time) {//time是接收输入的时间
    var date = +new Date();//获取总的毫秒数
    var date1 = +new Date(time);//获取输入的总的毫秒数
    var times = (date1 - date) / 1000;//输入的毫秒数-总的毫秒数  再除1000是求秒数，1s = 1000ms
    var h = parseInt(times / 60 / 60 % 24);
    lis[0].innerHTML = h >= 10 ? h : '0' + h;
    var m = parseInt(times / 60 % 60);
    lis[1].innerHTML = m >= 10 ? m : '0' + m;
    var s = parseInt(times % 60);
    lis[2].innerHTML = s >= 10 ? s : '0' + s;

}

